package com.example.service;

import com.example.entity.BooksCategory;
import com.example.entity.BooksContent;
import com.example.mapper.BooksContentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
章节内容业务处理
 */
@Service
public class BooksContentService {

    @Resource
    private BooksContentMapper booksContentMapper;

    public void add(BooksContent booksContent) {
        booksContentMapper.insert(booksContent);
    }

    public void deleteById(Integer id) {
        booksContentMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(BooksContent booksContent) {
        booksContentMapper.updateById(booksContent);
    }

    public BooksContent selectById(Integer id) {
        return booksContentMapper.selectById(id);
    }

    public List<BooksContent> selectAll(BooksContent booksContent) {
        return booksContentMapper.selectAll(booksContent);
    }

    public PageInfo<BooksContent> selectPage(BooksContent booksContent, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<BooksContent> booksContentList = booksContentMapper.selectAll(booksContent);
        return PageInfo.of(booksContentList);
    }
}
